#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "form.h"
#include <QMainWindow>
#include <QPixmap>
#include <QImage>
#include<QCamera>
#include<QCameraViewfinder>
#include<QCameraImageCapture>
#include <QWidget>
#include<QPushButton>
#define Nmax 60


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    QImage* Graychange(QImage *image);

    QImage* Bitchange3(QImage *image);

    QImage* Gausschange(QImage *image);

    QImage* findEdge(QImage *image);

    QImage* midchange(QImage *image);
   QImage* thin(QImage *image);
    QImage* findEdge_by_direction(QImage *image);
   // QImage* thin(QImage *image);
     void Print();
    typedef struct Node{
        double val[2][2];
        void show(){
            for(int i = 0 ; i < 2 ; i ++ ){
                for(int j = 0 ; j < 2 ; j ++ ){
                    printf("%.2lf,",this->val[i][j]);
                }
                printf("\n");
            }
        }
    }Node;

    typedef struct Ft{
        int val[3][3];
            int cnt;
    }Ft;

    int img[100][100];

    int table_erase[256]={
        0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1,
        1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,
        0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1,
        1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,
        1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        1,1,0,0,1,1,0,0,1,1,0,1,1,1,0,1,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1,
        1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,
        0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1,
        1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
        1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,
        1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
        1,1,0,0,1,1,0,0,1,1,0,1,1,1,0,0,
        1,1,0,0,1,1,1,0,1,1,0,0,1,0,0,0
    };




    QCamera *m_pCamera;    //获取摄像头
    QCameraViewfinder *m_pViewfinder;  //渲染摄像头
    QCameraImageCapture *m_pImageCapture;   //获取摄像头当前帧


private slots:
    void Init();
    void on_pushButton_addPicture_clicked();

    void on_pushButton_grayChange_clicked();

    void on_pushButton_bitChange3_clicked();

    void on_horizontalSlider_valueChanged(int value);

    void on_spinBox_valueChanged(int arg1);

    void on_pushButton_gaussChange_clicked();

    void on_pushButton_findEdge_clicked();

    void on_horizontalSlider_FindEdge_valueChanged(int value);

    void on_spinBox__FindEdge_valueChanged(const QString &arg1);

    void on_pushButton_cnn_clicked();

    void exitBtnResponded();
    void cameraImageCapture(int,QImage);
    void capture();

    void on_pushButton_carmera_clicked();

    void on_button2_clicked();

    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
    QPixmap pix;
    QImage image;
    QPixmap pix1;
    QImage image1;
    QPixmap pix2;
    QImage image2;
    QPixmap pix3;
    QImage image3;
    QPixmap pix4;
    QImage image4;
    QImage image5;
    QPixmap pix5;


    void findvalues(double image[Nmax][Nmax],Ft* Feat,Ft* Feat1, int len,Node* ans);

    void Smaller(double image[Nmax][Nmax],Ft* Feat, int len);

    void Merge(double tmp_img[Nmax][Nmax],double timg[Nmax][Nmax],int len);

    int Convolution(double image[Nmax][Nmax], Ft* Feat,int len);

    int Pooling(double image[Nmax][Nmax], int len);

    void ReLU(double image[Nmax][Nmax], int len, double hold);

    void Print(double image[Nmax][Nmax], int len);

    void bitChange(double image[Nmax][Nmax], int len, double hold);

    void bitChange1(double image[Nmax][Nmax], int len, double hold);

    void Bitchange(double image[Nmax][Nmax],QImage *img,int len);

    void enRose(double image[Nmax][Nmax],int len,int er[2]);
    char compare();

    void Thin2(double image[Nmax][Nmax],int len);
public:
    void findvalues1(int image[100][100],Ft* Feat,int len,Node* ans);

    void toMatr(QImage *image,int img[100][100]);
};

#endif // MAINWINDOW_H
